package com.isoft.service.impl;

import com.isoft.service.BaseApueService;
import com.isoft.service.XmlFileHandler;
import org.springframework.stereotype.Component;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.charset.StandardCharsets;

@Component
public class BaseApueFileHandler implements XmlFileHandler {
    private final BaseApueService baseApueService;

    public BaseApueFileHandler(BaseApueService baseApueService) {
        this.baseApueService = baseApueService;
    }

    @Override
    public boolean supports(Path filePath) {
        String name = filePath.getFileName().toString().toUpperCase();
        return name.startsWith("BASE-APUE") && name.endsWith(".XML");
    }

    @Override
    public String handle(Path filePath) throws Exception {
        // 读取文件内容为字符串
        String xmlContent = Files.readString(filePath, StandardCharsets.UTF_8);
        return baseApueService.parseAndSave(xmlContent);
    }
} 